const commoneUrl  = "https://mp.fangyiyun.com/mp/"; //公共路径 mp.fangyiyun.com    47.100.98.64

const userId = uni.getStorageSync("userinfo_Data").id //用户id

//post请求封装
function postRequest(url,data,type){
	var promise = new Promise((resolve,reject) => {
		var postData = data;
		uni.request({
			url:commoneUrl + url,
			data:postData,
			method:'POST',
			// dataType:"jsonp",
			// jsonp:"callbackparam",//传递给请求处理程序或页面的，用以获得jsonp回调函数名的参数名
			// jsonpCallback:"success_jsonpCallback",

			header:{
				'content-type': type || 'application/json;charset=UTF-8',
					// uid:uni.getStorageSync("uid"),
					// ct:'0',
					// mqcl:'mp-ha',
					
					mqcl:'mp-ha',
					uid:'ow7J85PQNHS--M8lAQRa437x0WNg',
					cdk:'N4Wa+kIXSJSGw+APdEPCeIZBNaLhJfk0'
					
				// ,'token':uni.getStorageSync('token')
				}, //token可以不要，看后端
			success:function(res){
				// console.log("ddd",res);
				if(res.statusCode == 200){
					resolve(res.data);
				}else{
					if(res.data){
						uni.showToast({
							title: res.data,
							icon: 'none'
						})
					}else{
						uni.showToast({
							title: "网络出错，请稍后再试",
							icon: 'none'
						})
					}
					// reject('网络出错');
				}
				
			},
			error:function(e)
			{
				reject('网络出错');
			}
		})
	});
	return promise;
}


//get请求封装
function getRequest(url,data,type){
	var promise = new Promise((resolve,reject) => {
			var postData = data;
			uni.request({
				url:commoneUrl + url,
				data:postData,
				method:"GET",
				dataType:'json',
				header:{
					'content-type': type || 'application/json;charset=UTF-8',
					
					mqcl:'mp-ha',
					uid:'ow7J85PQNHS--M8lAQRa437x0WNg',
					cdk:'N4Wa+kIXSJSGw+APdEPCeIZBNaLhJfk0',
					ct:'0',
					
					// uid:uni.getStorageSync("uid"),
					
					// mqcl:'mp-ha'
				// ,'token':uni.getStorageSync('token')
				},
				success:function(res){
					// resolve(res);
					if(res.statusCode == 200){
						resolve(res);
					}else{
						if(res.data){
							uni.showToast({
								title: res.data,
								icon: 'none'
							})
						}else{
							uni.showToast({
								title: "网络出错，请稍后再试",
								icon: 'none'
							})
						}
						// reject('网络出错');
					}
					
				},
				error:function(e)
				{
					reject('网络出错');
				}
			});
	});
	return promise;
}
//put请求封装
function putRequest(url,data){
	var promise = new Promise((resolve,reject) => {
			var postData = data;
			uni.request({
				url:commoneUrl + url,
				data:postData,
				method:"PUT",
				dataType:'json',
				header:{
					'content-type': 'application/json',
					uid:uni.getStorageSync("uid"),
					ct:'0',
					mqcl:'mp-ha'
					// ,'token': uni.getStorageSync('token')
					},
				success:function(res){
					resolve(res.data);
					
				},error:function(e){
					reject('网络出错');
				}
			});
	});
	return promise;
}
//del请求封装
function delRequest(url,data){
	var promise = new Promise((resolve,reject) => {
			var postData = data;
			uni.request({
				url:commoneUrl + url,
				data:postData,
				method:"DELETE",
				dataType:'json',
				header:{
					'content-type': 'application/json',
					uid:uni.getStorageSync("uid"),
					ct:'0',
					mqcl:'mp-ha'
					// ,'token': uni.getStorageSync('token')
					},
				success:function(res){
					resolve(res.data);
				
				},error:function(e){
					reject('网络出错');
				}
			});
	});
	return promise;
}
module.exports = {
    post: postRequest,
    get: getRequest,
	put: putRequest,
	del: delRequest,
	ip: commoneUrl,
	userId : userId
};
